<?php
/**
 *
 * 导入数据库
 *
 * Created by Yxl.
 * User: <zccem@163.com>.
 * Date: 2017/8/30
 * Time: 10:18
 */

?>

<span style="font-size:18px;">

    <?php

    $dbhost = "sdm218631644.my3w.com";
    $dbuser = "sdm218631644";
    $dbpassword = "fanchen2011";
    $dbdatabase = "sdm218631644_db";

    $db_restore_success = true;
    $sql_file_name = "20170825154954.sql";

    $con = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbdatabase);

    $db_selected = mysqli_select_db($con, $dbdatabase);//选择数据库
    if (!$db_selected || !$con) {
        $db_restore_success = false;
    } else {
        $sql = file_get_contents($sql_file_name); //把SQL语句以字符串读入$sql
        $a = explode(";", $sql); //用explode()函数把‍$sql字符串以“;”分割为数组

        // 遍历数组
        foreach ($a as $b) {
            $c = $b . ";"; // 分割后是没有“;”的，因为SQL语句以“;”结束，所以在执行SQL前把它加上
            $result = mysqli_query($con, $c); //执行SQL语句

            $db_restore_success = $db_restore_success && $result;
        }
    }

    if ($db_restore_success)//输出恢复情况
        echo '{"status":"success"}';
    else
        echo '{"status":"failed"}';

    ?>

</span>
